View Javadoc

1   /*
2    * Copyright (c) 2004-2005, University Health Network.  All rights reserved. Distributed under the BSD 
3    * license (see http://opensource.org/licenses/bsd-license.php).
4    *  
5    * StringParamField.java
6    *
7    * Created on 15-Dec-2004 at 1:41:29 PM
8    */
9   package ca.uhn.cache.internal.hibernate.impl;
10  
11  import java.util.Map;
12  
13  import org.apache.commons.lang.builder.EqualsBuilder;
14  import org.apache.commons.lang.builder.HashCodeBuilder;
15  import org.apache.commons.lang.builder.ToStringBuilder;
16  
17  import ca.uhn.cache.IDimension;
18  import ca.uhn.cache.IQueryParam;
19  import ca.uhn.cache.impl.StringParam;
20  
21  
22  
23  /***
24   * Hibernate persistable object with xdoclet annotations for <code>StringParam</code>. 
25   * 
26   * @author <a href="mailto:alexei.guevara@uhn.on.ca">Alexei Guevara</a>
27   * @version $Revision: 1.1 $ updated on $Date: 2005/01/24 22:52:40 $ by $Author: bryan_tripp $
28   * 
29   * @hibernate.joined-subclass table="string_param_field"
30   * @hibernate.joined-subclass-key column="string_param_field_id"
31   */
32  public class StringParamField extends Field {
33      
34      private String myValue;
35      
36      /***
37       * Constructs a <code>StringParamField</code> from a source <code>StringParam</code>.
38       * 
39       * @param theRecord The record this field belongs to.
40       * @param theParam The source <code>StringParam</code>.
41       */
42      public StringParamField( Record theRecord, StringParam theParam ) {
43          super( theRecord, theParam.getDimension().getName() );
44          setValue( theParam.getValue() );
45      }
46      
47      /***
48       */
49      public StringParamField() {
50          super( null, null );
51      }
52  
53      /***
54       * @return Returns the value.
55       * 
56       * @hibernate.property not-null="true"
57       */
58      public String getValue() {
59          return myValue;
60      }
61      /***
62       * @param theValue The value to set.
63       */
64      public void setValue( String theValue ) {
65          myValue = theValue;
66      }
67  
68      /***
69       * {@inheritDoc}
70       */
71      public IQueryParam toQueryParam( Map theDimensionNameToDimensionMap ) {
72          return new StringParam( (IDimension) theDimensionNameToDimensionMap.get( getDimensionName() ), getValue() );
73      }
74      
75      /***
76       * {@inheritDoc}
77       */
78      public int hashCode() {
79          return new HashCodeBuilder()
80                      .appendSuper( super.hashCode() )
81                      .append( getValue() ).toHashCode();
82      }
83      
84      
85      /***
86       * {@inheritDoc}
87       */
88      public boolean equals( Object theObj ) {
89          boolean retVal = false;
90          if (theObj instanceof StringParamField) {
91              StringParamField otherField = (StringParamField) theObj;
92              retVal = new EqualsBuilder()
93                  .appendSuper( super.equals(theObj) )
94                  .append( getValue(), otherField.getValue() ).isEquals();
95          }
96          return retVal;
97      }
98      
99      
100     /***
101      * {@inheritDoc}
102      */
103     public String toString() {
104         return new ToStringBuilder( this )
105                     .appendSuper( super.toString() )
106                     .append( getValue() ).toString();
107     }
108     
109 }